import { jsonPost, ajaxGet} from '@/util'
import { resolve } from 'tinymce'
export default({
  state: {
    depart: [],
    flowTypeList: [],
    flowCreatorList: [],
    cycleList: [],
    storeTypeList: [],
    brandCycleList: []
  },
  mutations: {
    setListDepartmentTree(state, res) {
      state.depart = res
    }
  },
  actions: {
    // 科室
    getListDepartmentTree ({commit, state}, params) {
      if (!state.depart.length) {
        jsonPost("/department/listDepartmentTree").then(res=> {
          commit('setListDepartmentTree', res)
        })
      }
    },
    // 科室下面的经销商
    getDistributorDepartment({commit, state}, params) {
      return new Promise((resolve, reject) => {
        jsonPost("/department/queryDistributorDepartment", params).then(res => {
          resolve(res.records)
        })
      })
    },
    // 返利类型
    getFlowTypeList({commit, state}, params) {
      return new Promise((resolve, reject) => {
        jsonPost('/distributor/rebate/flow/findRebateFlowTypeList', params).then(res => {
          state.flowTypeList = res.records
          resolve(res.records)
        })
      })
    },
    // 维护人
    getCreatorList({commit, state}, params) {
      return new Promise((resolve, reject) => {
        jsonPost('/distributor/rebate/flow/findRebateFlowCreatorList', params).then(res => {
          state.flowCreatorList = res
        })
      })
    },
    // 周期
    getCycle({commit, state}, params) {
      return new Promise((resolve, reject) => {
        ajaxGet('/salesman/inspection/distributor_inspection_period/list', params).then(res => {
          // state.cycleList = (res || []).map(item => {
          //   return {
          //     ...item,
          //     text: item.beginYearMonth + '~' + item.endYearMonth
          //   }
          // })
          resolve(res)
        })
      })
    },
    // 门店类型列表
    getStoreTypeList({commit, state}, params) {
      return new Promise((resolve, reject) => {
        ajaxGet('/salesman/inspection/store_types').then(res => {
          state.storeTypeList = res
        })
      })
    },
    // 品牌商周期
    getBrandCycle({commit, state}, params) {
      return new Promise((resolve, reject) => {
        ajaxGet('/salesman/inspection/supplier_inspection_period/list', params).then(res => {
          state.brandCycleList = (res || []).map(item => {
            return {
              ...item,
              text: item.beginYearMonth + '~' + item.endYearMonth
            }
          })
          resolve(res)
        })
      })
    }
  },
  getters: {
    reportDepart(state, getters) {
      return state.depart
    },
    reportFlowTypeList(state, getters) {
      return state.flowTypeList
    },
    reportFlowCreatorList(state, getters) {
      return state.flowCreatorList
    },
    reportCycleList(state, getters) {
      return state.cycleList
    },
    reportStoreTypeList(state, getters) {
      return state.storeTypeList
    },
    reportBrandCycleList(state, getters) {
      return state.brandCycleList
    }
  }
})